import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.Writer;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;


public class VelocityTest {
	public static void main(String[] str) {
		 
        //½¨Á¢Ä£°åÒýÇæ¶ÔÏó
        VelocityEngine ve = new VelocityEngine();
        // Ä£°åÎÄ¼þËùÔÚµÄÂ·¾¶
        String path = "src";
        // ÉèÖÃ²ÎÊý
        ve.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
        // ´¦ÀíÖÐÎÄÎÊÌâ
        ve.setProperty(Velocity.INPUT_ENCODING, "GBK");
        ve.setProperty(Velocity.OUTPUT_ENCODING, "GBK");

        try {
            //Ä£°å³õÊ¼»¯
            ve.init();
            //»ñÈ¡Ä£°å
            Template template = ve.getTemplate("test.vm");
 
 
            //»ñÈ¡ÉÏÏÂÎÄ
            VelocityContext velocityContext = new VelocityContext();
            //Ìî³äÊý¾Ýµ½ÉÏÏÂÎÄ£¬ÕâÀïÃæµÄkeyÎªÄ£°åÎÄ¼þÖÐ¶¨ÒåµÄ$name
            velocityContext.put("count", "ËÄÚÐ·¨");

 
            //ÉèÖÃÊä³öÎÄ¼þ
            String outPath = "src/test.html";
            //´´½¨Êä³ö¶ÔÏó
            Writer mywriter = new PrintWriter(new FileOutputStream(new File(outPath)));
            //Êý¾ÝÈÚºÏ
            template.merge(velocityContext, mywriter);
            //¹Ø±ÕÊä³öÁ÷
            mywriter.flush();
            mywriter.close();
			
			// test svn modifying!
         
         
      // modified online!
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
